/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.events;

import java.util.Map;

/**
 * <p>This is a subclass of XREEvent that represents the "onVideoStatus" event. It defines some properties specific to
 * this event. Note that values of all custom properties are actually stored in the XREEvent#params map.</p>
 *
 * <p><strong>Thread safety:</strong> This class is mutable and not thread safe.</p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
@SuppressWarnings("boxing")
public class XREVideoStatusEvent extends XREResourceEvent {

    /**
     * <p>Represents the name of the "on video status" event.</p>
     *
     * <p>This is a string constant used by the user when setting the name of the event.</p>
     */
    public static final String ON_VIDEO_STATUS_EVENT_NAME = "onVideoStatus";

    /**
     * <p>Represents the name used to retrieve the width parameter.</p>
     */
    private static final String WIDTH = "width";

    /**
     * <p>Represents the name used to retrieve the height parameter.</p>
     */
    private static final String HEIGHT = "height";

    /**
     * <p>Represents the name used to retrieve the duration parameter.</p>
     */
    private static final String DURATION = "duration";

    /**
     * <p>Represents the name used to retrieve the position parameter.</p>
     */
    private static final String POSITION = "position";

    /**
     * <p>Represents the name used to retrieve the live parameter.</p>
     */
    private static final String IS_LIVE = "isLive";

    /**
     * <p>Represents the name used to retrieve the buffering parameter.</p>
     */
    private static final String IS_BUFFERING = "isBuffering";

    /**
     * <p>Represents the name used to retrieve the buffer percentage parameter.</p>
     */
    private static final String BUFFER_PERCENTAGE = "bufferPercentage";

    /**
     * <p>Represents the name used to retrieve the connection url parameter.</p>
     */
    private static final String CONNECTION_URL = "connectionURL";

    /**
     * <p>Represents the name used to retrieve the dynamic properties parameter.</p>
     */
    private static final String DYNAMIC_PROPS = "dynamicProps";

    /**
     * <p>Represents the name used to retrieve the net stream info parameter.</p>
     */
    private static final String NET_STREAM_INFO = "netStreamInfo";

    /**
     * <p>Creates new instance of {@link XREVideoStatusEvent} class.</p>
     */
    public XREVideoStatusEvent() {
        // empty constructor
    }

    /**
     * <p>Retrieves the native width of the video, in pixels, before scaling or fitting.</p>
     *
     * @return the native width of the video, in pixels, before scaling or fitting
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public double getWidth() {
        return getTypedParam(WIDTH, Double.class);
    }

    /**
     * <p>Sets the native width of the video, in pixels, before scaling or fitting.</p>
     *
     * @param width the native width of the video, in pixels, before scaling or fitting
     *
     * @throws IllegalStateException if params is null
     */
    public void setWidth(double width) {
        setParam(WIDTH, width);
    }

    /**
     * <p>Retrieves the native height of the video, in pixels, before scaling or fitting.</p>
     *
     * @return the native height of the video, in pixels, before scaling or fitting
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public double getHeight() {
        return getTypedParam(HEIGHT, Double.class);
    }

    /**
     * <p>Sets the native height of the video, in pixels, before scaling or fitting.</p>
     *
     * @param height the native height of the video, in pixels, before scaling or fitting
     *
     * @throws IllegalStateException if params is null
     */
    public void setHeight(double height) {
        setParam(HEIGHT, height);
    }

    /**
     * <p>Retrieves the duration of the video, in milliseconds.</p>
     *
     * @return the duration of the video, in milliseconds
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public double getDuration() {
        return getTypedParam(DURATION, Double.class);
    }

    /**
     * <p>Sets the duration of the video, in milliseconds.</p>
     *
     * @param duration the duration of the video, in milliseconds
     *
     * @throws IllegalStateException if params is null
     */
    public void setDuration(double duration) {
        setParam(DURATION, duration);
    }

    /**
     * <p>Retrieves the current position of the playhead, in milliseconds.</p>
     *
     * @return the current position of the playhead, in milliseconds
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public double getPosition() {
        return getTypedParam(POSITION, Double.class);
    }

    /**
     * <p>Sets the current position of the playhead, in milliseconds.</p>
     *
     * @param position the current position of the playhead, in milliseconds
     *
     * @throws IllegalStateException if params is null
     */
    public void setPosition(double position) {
        setParam(POSITION, position);
    }

    /**
     * <p>Retrieves the flag indicating whether the content is a live stream.</p>
     *
     * @return the flag indicating whether the content is a live stream
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public boolean isLive() {

        return getTypedParam(IS_LIVE, Boolean.class);
    }

    /**
     * <p>Sets the flag indicating whether the content is a live stream.</p>
     *
     * @param live the flag indicating whether the content is a live stream
     *
     * @throws IllegalStateException if params is null
     */
    public void setLive(boolean live) {

        setParam(IS_LIVE, live);
    }

    /**
     * <p>Retrieves the flag indicating whether the video has been temporarily passed while it loads data into its
     * buffer.</p>
     *
     * @return the flag indicating whether the video has been temporarily passed while it loads data into its buffer
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public boolean isBuffering() {

        return getTypedParam(IS_BUFFERING, Boolean.class);
    }

    /**
     * <p>Sets the flag indicating whether the video has been temporarily passed while it loads data into its
     * buffer.</p>
     *
     * @param buffering the flag indicating whether the video has been temporarily passed while it loads data into its
     *                  buffer
     *
     * @throws IllegalStateException if params is null
     */
    public void setBuffering(boolean buffering) {

        setParam(IS_BUFFERING, buffering);
    }

    /**
     * <p>Retrieves the percentage of the video that has been buffered.</p>
     *
     * @return the percentage of the video that has been buffered
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public double getBufferPercentage() {

        return getTypedParam(BUFFER_PERCENTAGE, Double.class);
    }

    /**
     * <p>Sets the percentage of the video that has been buffered.</p>
     *
     * @param bufferPercentage the percentage of the video that has been buffered
     *
     * @throws IllegalStateException if params is null
     */
    public void setBufferPercentage(double bufferPercentage) {

        setParam(BUFFER_PERCENTAGE, bufferPercentage);
    }

    /**
     * <p>Retrieves the URL of the video content, after all redirects have been followed.</p>
     *
     * @return the URL of the video content
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getConnectionURL() {

        return getTypedParam(CONNECTION_URL, String.class);
    }

    /**
     * <p>Sets the URL of the video content, after all redirects have been followed.</p>
     *
     * @param connectionURL the URL of the video content
     *
     * @throws IllegalStateException if params is null
     */
    public void setConnectionURL(String connectionURL) {

        setParam(CONNECTION_URL, connectionURL);
    }

    /**
     * <p>Retrieves the map with properties for a piece of video content that supports dynamic stream switching.</p>
     *
     * @return the map with properties for a piece of video content that supports dynamic stream switching
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    @SuppressWarnings("unchecked")
    public Map<String, Object> getDynamicProps() {

        return getTypedParam(DYNAMIC_PROPS, Map.class);
    }

    /**
     * <p>Sets the map with properties for a piece of video content that supports dynamic stream switching.</p>
     *
     * @param dynamicProps the map with properties for a piece of video content that supports dynamic stream switching
     *
     * @throws IllegalStateException if params is null
     */
    public void setDynamicProps(Map<String, Object> dynamicProps) {
        setParam(DYNAMIC_PROPS, dynamicProps);
    }

    /**
     * <p>Retrieves the map that contains additional information about the video stream provided by the Flash NetStream
     * object.</p>
     *
     * @return the map that contains additional information about the video stream provided by the Flash NetStream
     *         object
     *
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    @SuppressWarnings("unchecked")
    public Map<String, Object> getNetStreamInfo() {

        return getTypedParam(NET_STREAM_INFO, Map.class);
    }

    /**
     * <p>Sets the map that contains additional information about the video stream provided by the Flash NetStream
     * object.</p>
     *
     * @param netStreamInfo the map that contains additional information about the video stream provided by the Flash
     *                      NetStream object
     *
     * @throws IllegalStateException if params is null
     */
    public void setNetStreamInfo(Map<String, Object> netStreamInfo) {
        setParam(NET_STREAM_INFO, netStreamInfo);
    }
}

